package io.gitee.kenewstar.dbmq.data;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author kenewstar
 */
public class DbDataHandlerWrapper {

    private static final Logger LOGGER = LoggerFactory.getLogger(DbDataHandlerWrapper.class);

    public static final String MYSQL = "mysql";
    public static final String MONGO = "mongo";
    public static final String REDIS = "redis";

    private final Map<String, DbDataHandler> handlerMap;

    public DbDataHandlerWrapper(List<DbDataHandler> handlerList) {
        for (DbDataHandler dbDataHandler : handlerList) {
            LOGGER.info("------------Load {} DbDataHandler------------------", dbDataHandler.getType());
        }
        this.handlerMap = handlerList.stream().collect(Collectors.toMap(DbDataHandler::getType, Function.identity()));
    }

    public DbDataHandler toHandler(String type) {
        LOGGER.info("------------DbDataHandler type is {}------------------", type);
        return handlerMap.get(type);
    }

}
